From e71bcc8487b3e72504e657796dd2abbe7a2babc1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Nov 2003 20:53:03 +0000 Subject: [PATCH] Changes to improve menu positioning on Xinerama (#108328): Wed Nov 12 21:40:10 2003 Matthias Clasen Changes to improve menu positioning on Xinerama (#108328): * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field to store the monitor on which the menu is to be positioned. * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number in the GtkMenuPrivate struct and fetch the monitor geometry after calling the position_func, in case it has been changed. * gtk/gtkmenu.c (gtk_menu_set_monitor): New function to be used in GtkMenuPositionFunc implementations for setting the monitor_num field in GtkMenuPrivate. * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call gtk_menu_set_monitor. --- ChangeLog | 18 ++++++++++++ ChangeLog.pre-2-10 | 18 ++++++++++++ ChangeLog.pre-2-4 | 18 ++++++++++++ ChangeLog.pre-2-6 | 18 ++++++++++++ ChangeLog.pre-2-8 | 18 ++++++++++++ docs/reference/ChangeLog | 4 +++ docs/reference/gtk/gtk-sections.txt | 1 + gtk/gtkmenu.c | 44 +++++++++++++++++++++++++---- gtk/gtkmenu.h | 2 ++ gtk/gtkmenuitem.c | 2 ++ 10 files changed, 138 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57d4b3d22c..7bc003ed56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +Wed Nov 12 21:40:10 2003 Matthias Clasen + + Changes to improve menu positioning on Xinerama (#108328): + + * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field + to store the monitor on which the menu is to be positioned. + + * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number + in the GtkMenuPrivate struct and fetch the monitor geometry after + calling the position_func, in case it has been changed. + + * gtk/gtkmenu.c (gtk_menu_set_monitor): New function + to be used in GtkMenuPositionFunc implementations for setting + the monitor_num field in GtkMenuPrivate. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call + gtk_menu_set_monitor. + Wed Nov 12 21:00:10 2003 Matthias Clasen * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 57d4b3d22c..7bc003ed56 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,21 @@ +Wed Nov 12 21:40:10 2003 Matthias Clasen + + Changes to improve menu positioning on Xinerama (#108328): + + * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field + to store the monitor on which the menu is to be positioned. + + * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number + in the GtkMenuPrivate struct and fetch the monitor geometry after + calling the position_func, in case it has been changed. + + * gtk/gtkmenu.c (gtk_menu_set_monitor): New function + to be used in GtkMenuPositionFunc implementations for setting + the monitor_num field in GtkMenuPrivate. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call + gtk_menu_set_monitor. + Wed Nov 12 21:00:10 2003 Matthias Clasen * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 57d4b3d22c..7bc003ed56 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,21 @@ +Wed Nov 12 21:40:10 2003 Matthias Clasen + + Changes to improve menu positioning on Xinerama (#108328): + + * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field + to store the monitor on which the menu is to be positioned. + + * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number + in the GtkMenuPrivate struct and fetch the monitor geometry after + calling the position_func, in case it has been changed. + + * gtk/gtkmenu.c (gtk_menu_set_monitor): New function + to be used in GtkMenuPositionFunc implementations for setting + the monitor_num field in GtkMenuPrivate. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call + gtk_menu_set_monitor. + Wed Nov 12 21:00:10 2003 Matthias Clasen * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 57d4b3d22c..7bc003ed56 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,21 @@ +Wed Nov 12 21:40:10 2003 Matthias Clasen + + Changes to improve menu positioning on Xinerama (#108328): + + * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field + to store the monitor on which the menu is to be positioned. + + * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number + in the GtkMenuPrivate struct and fetch the monitor geometry after + calling the position_func, in case it has been changed. + + * gtk/gtkmenu.c (gtk_menu_set_monitor): New function + to be used in GtkMenuPositionFunc implementations for setting + the monitor_num field in GtkMenuPrivate. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call + gtk_menu_set_monitor. + Wed Nov 12 21:00:10 2003 Matthias Clasen * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 57d4b3d22c..7bc003ed56 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,21 @@ +Wed Nov 12 21:40:10 2003 Matthias Clasen + + Changes to improve menu positioning on Xinerama (#108328): + + * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field + to store the monitor on which the menu is to be positioned. + + * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number + in the GtkMenuPrivate struct and fetch the monitor geometry after + calling the position_func, in case it has been changed. + + * gtk/gtkmenu.c (gtk_menu_set_monitor): New function + to be used in GtkMenuPositionFunc implementations for setting + the monitor_num field in GtkMenuPrivate. + + * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call + gtk_menu_set_monitor. + Wed Nov 12 21:00:10 2003 Matthias Clasen * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 64a9ce7bcb..95fa449a0e 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +Wed Nov 12 21:52:35 2003 Matthias Clasen + + * gtk/gtk-sections.txt: Add gtk_menu_set_monitor. + Fri Oct 24 13:15:32 2003 Soeren Sandmann * gtk/tmpl/gtktoolbar.sgml, gtk/tmpl/gtkseparatortoolitem.sgml: diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index cf64afaf35..f78d2cb1f2 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -1865,6 +1865,7 @@ gtk_menu_detach gtk_menu_get_attach_widget GtkMenuPositionFunc GtkMenuDetachFunc +gtk_menu_set_monitor GTK_MENU GTK_IS_MENU diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index 263d079b16..1d0bcf2b95 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -84,6 +84,8 @@ struct _GtkMenuPrivate guint *heights; gint heights_length; + + gint monitor_num; }; typedef struct @@ -3064,7 +3066,6 @@ gtk_menu_position (GtkMenu *menu) GdkScreen *screen; GdkScreen *pointer_screen; GdkRectangle monitor; - gint monitor_num; g_return_if_fail (GTK_IS_MENU (menu)); @@ -3092,13 +3093,16 @@ gtk_menu_position (GtkMenu *menu) y = MAX (0, (gdk_screen_get_height (screen) - requisition.height) / 2); } - monitor_num = gdk_screen_get_monitor_at_point (screen, x, y); - gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + private = gtk_menu_get_private (menu); + private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y); push_in = FALSE; if (menu->position_func) - (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data); + { + (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data); + gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor); + } else { gint space_left, space_right, space_above, space_below; @@ -3126,6 +3130,8 @@ gtk_menu_position (GtkMenu *menu) * Positioning in the vertical direction is similar: first try below * mouse cursor, then above. */ + gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor); + space_left = x - monitor.x; space_right = monitor.x + monitor.width - x - 1; space_above = y - monitor.y; @@ -3239,7 +3245,6 @@ gtk_menu_position (GtkMenu *menu) if (GTK_MENU_SHELL (menu)->active) { - private = gtk_menu_get_private (menu); private->have_position = TRUE; private->x = x; private->y = y; @@ -3957,3 +3962,32 @@ gtk_menu_real_move_scroll (GtkMenu *menu, break; } } + + +/** + * gtk_menu_set_monitor: + * @menu: a #GtkMenu + * @monitor_num: the number of the monitor on which the menu should + * be popped up + * + * Informs GTK+ on which monitor a menu should be popped up. + * See gdk_screen_get_monitor_geometry(). + * + * This function should be called from a #GtkMenuPositionFunc if the + * menu should not appear on the same monitor as the pointer. This + * information can't be reliably inferred from the coordinates returned + * by a #GtkMenuPositionFunc, since, for very long menus, these coordinates + * may extend beyond the monitor boundaries or even the screen boundaries. + * + * Since: 2.4 + **/ +void gtk_menu_set_monitor (GtkMenu *menu, + gint monitor_num) +{ + GtkMenuPrivate *priv; + g_return_if_fail (GTK_IS_MENU (menu)); + + priv = gtk_menu_get_private (menu); + + priv->monitor_num = monitor_num; +} diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h index b430254ba3..5701f5cc9a 100644 --- a/gtk/gtkmenu.h +++ b/gtk/gtkmenu.h @@ -196,6 +196,8 @@ void gtk_menu_attach (GtkMenu *menu, guint top_attach, guint bottom_attach); +void gtk_menu_set_monitor (GtkMenu *menu, + gint monitor_num); #ifndef GTK_DISABLE_DEPRECATED #define gtk_menu_append(menu,child) gtk_menu_shell_append ((GtkMenuShell *)(menu),(child)) diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index eca9b46629..312c511070 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -1108,6 +1108,8 @@ gtk_menu_item_position_menu (GtkMenu *menu, */ *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth)); *y = ty; + + gtk_menu_set_monitor (menu, monitor_num); } /** -- 2.30.2